<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AdminAdminUser
 *
 * @author Admin
 */
class Main_Resource_Adminuser extends WOW_Model_Resource_Db_Table_Abstract implements
Main_Resource_AdminUser_Interface
{
    protected $_name = 'admin_users';
    protected $_primary = 'id';
    protected $_rowClass = 'Main_Resource_AdminUser_Item';

    public function getUserById($id)
    {
        return $this->find($id)->current();
    }

    public function getUserByUserName($name, $ignoreUser=null)
    {
        $select = $this->select();
        $select->where('AdminUserName = ?', $name);

        if (null !== $ignoreUser) {
            $select->where('AdminUserName != ?', $ignoreUser->AdminUserName);
        }
         return $this->fetchRow($select);
    }

    public function getUserByUserNamePassword($name, $pwd)
    {
         $select = $this->select()->where('AdminUserName = ? ', $name)
                 ->where('Password = ? ', $pwd);
        return $this->fetchRow($select);
    }

    public function getAllUsers($paged=false, $order=null)
    {
         $select = $this->select();

        if (true === is_array($order)) {
            $select->order($order);
        }

        if (null !== $paged)
        {
            $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
            $count = clone $select;
            $count->reset(Zend_Db_Select::COLUMNS);
            $count->reset(Zend_Db_Select::FROM);
            $count->from('admin_users', new Zend_Db_Expr('COUNT(*) AS `zend_paginator_row_count`'));
            $adapter->setRowCount($count);

            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(10)
                      ->setCurrentPageNumber((int) $paged);
            return $paginator;
	}
        return $this->fetchAll($select);
    }
}
?>
